package com.joyintech.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.joyintech.feign.BatchService;
import com.joyintech.util.Verify;
import com.joyintech.vo.*;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Log4j2
@RestController
@RequestMapping("/batch")
public class BatchController {

    @Autowired
    private BatchService batchService;

    @PostMapping(value = "/verify", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String verify(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        log.info("解密之后报文->{}",decMessage);
        String custNo = Verify.verifyCbankWeb3Token(decMessage);
        log.info("生成客户号->{}",custNo);
        TokenVo tokenVo = new TokenVo();
        tokenVo.setCustNo(custNo);
        decMessage = JSON.toJSONString(tokenVo);
        TokenVo vo = JSON.parseObject(decMessage, TokenVo.class);
        log.info("请求报文 {}", JSON.toJSONString(vo));
        String result = batchService.verify(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/init", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String init(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        InitVo vo = JSON.parseObject(decMessage, InitVo.class);
        String result = batchService.init(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }


    @PostMapping(value = "/summaryQuery", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String summaryQuery(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        com.joyintech.vo.summaryQuery.Request vo = JSON.parseObject(decMessage, com.joyintech.vo.summaryQuery.Request.class);
        String result = batchService.summaryQuery(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/getProdById", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getProdById(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        GetProdByIdVo vo = JSON.parseObject(decMessage, GetProdByIdVo.class);
        String result = batchService.getProdById(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/commandProd", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String commandProd(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        CommandProdVo vo = JSON.parseObject(decMessage, CommandProdVo.class);
        String result = batchService.commandProd(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/notionalH5", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String notionalH5(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        Map<String, Object> map = JSON.parseObject(decMessage, HashMap.class);
        String result = batchService.notionalH5(map);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/getDict", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getDict(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        List<String> lists = JSONObject.parseArray(decMessage, String.class);
        String result = batchService.getDict(lists);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    /**
     * 数据为空  传 {}
     *
     * @param message
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/mstNewsSelect", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String mstNewsSelect(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);

        String result = batchService.mstNewsSelect();
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/dwdAstPlanGetId", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String dwdAstPlanGetId(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        ManagementVo vo = JSON.parseObject(decMessage, ManagementVo.class);
        String result = batchService.dwdAstPlanGetId(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    /**
     * 数据为空  传 {}
     *
     * @param message
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/reading", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String reading(@RequestBody String message) throws Exception {

        String decMessage = Verify.decMessage(message);
        String result = batchService.reading();
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/investmentSave", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String investmentSave(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        CustomerInvestmentProfileVo vo = JSON.parseObject(decMessage, CustomerInvestmentProfileVo.class);
        String result = batchService.investmentSave(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/investmentSelectById", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String investmentSelectById(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);

        String result = batchService.investmentSelectById(decMessage);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/investmentList", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String investmentList(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        CustomerInvestmentProfileVo vo = JSON.parseObject(decMessage, CustomerInvestmentProfileVo.class);
        String result = batchService.investmentList(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/investmentRemoveById", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String investmentRemoveById(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);

        String result = batchService.investmentRemoveById(decMessage);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/scoringQueryPage", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String scoringQueryPage(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        DwdAstPlanManagementPageVo vo = JSON.parseObject(decMessage, DwdAstPlanManagementPageVo.class);

        String result = batchService.scoringQueryPage(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/fundHold", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String fundHold(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        com.joyintech.vo.fundHold.Request vo = JSON.parseObject(decMessage, com.joyintech.vo.fundHold.Request.class);
        String result = batchService.fundHold(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/fcPosInq", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String fcPosInq(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        com.joyintech.vo.fcPosInq.Request vo = JSON.parseObject(decMessage, com.joyintech.vo.fcPosInq.Request.class);
        String result = batchService.fcPosInq(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/position", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String position(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        com.joyintech.vo.preciousMetal03.Request vo = JSON.parseObject(decMessage, com.joyintech.vo.preciousMetal03.Request.class);
        String result = batchService.position(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/policyInquiry", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String policyInquiry(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        com.joyintech.vo.policyInquiry.Request vo = JSON.parseObject(decMessage, com.joyintech.vo.policyInquiry.Request.class);
        String result = batchService.policyInquiry(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/fundHoldAm", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String fundHoldAm(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        com.joyintech.vo.fundHold.Request vo = JSON.parseObject(decMessage, com.joyintech.vo.fundHold.Request.class);
        String result = batchService.fundHoldAm(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/overviewOfWealth", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String overviewOfWealth(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        com.joyintech.vo.overviewOfWealth.Request vo = JSON.parseObject(decMessage, com.joyintech.vo.overviewOfWealth.Request.class);
        String result = batchService.overviewOfWealth(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }

    @PostMapping(value = "/fundZlCc", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String fundZlCc(@RequestBody String message) throws Exception {
        String decMessage = Verify.decMessage(message);
        com.joyintech.vo.fundZlCc.Request vo = JSON.parseObject(decMessage, com.joyintech.vo.fundZlCc.Request.class);
        String result = batchService.fundZlCc(vo);
        log.info("{}", JSON.toJSONString(result));
        JSONObject jsonObject = JSON.parseObject(result);
        String response = Verify.encMessage(jsonObject.toJSONString());
        return response;
    }
}
